<?php
/**
 * argv tid,mid,pid,type,sids
 *
 */
set_time_limit(0);
ini_set("memory_limit", -1);

$s = microtime(true);
echo '开发发送邮件,' . date("Y-m-d H:i:s") . "\n";

$cfg = array();
$cfg['mail'] = array();
$cfg['mail']['smtp'] = 'mail.qq.com';			// smtp服务器
$cfg['mail']['auth'] = true;					// 是否需要验证
$cfg['mail']['user'] = "2353987034@qq.com";	// 账号
$cfg['mail']['password'] = "zhongcai";			// 密码
$cfg['mail']['from'] = $cfg['mail']['user'];	// 发件人
$cfg['mail']['fromname'] = "2353987034@qq.com";// 发件人名称

// 库文件
require_once 'mail/class.phpmailer.php';


$mail = new PHPMailer();

if ($cfg['debug'])
	$mail->SMTPDebug = 2;

$mail->SMTPKeepAlive = true;
$mail->IsSMTP();					// 启用SMTP
$mail->Host = $cfg['mail']['smtp'];			//SMTP服务器
$mail->SMTPAuth = $cfg['mail']['auth'];					//开启SMTP认证
$mail->Username = $cfg['mail']['user'];			// SMTP用户名
$mail->Password = $cfg['mail']['password'];				// SMTP密码
$mail->From = $cfg['mail']['from'];			//发件人地址
$mail->FromName = $cfg['mail']['fromname'];				//发件人

$mail->WordWrap = 80;					//设置每行字符长度

$mail->CharSet = "utf-8";				// 这里指定字符集！
$mail->Encoding = "base64"; 
$mail->IsHTML(true);					// 是否HTML格式邮件

/** 附件设置
$mail->AddAttachment("/var/tmp/file.tar.gz");		// 添加附件
$mail->AddAttachment("/tmp/image.jpg", "new.jpg");	// 添加附件,并指定名称
*/

$mail->Subject = '圣诞快乐！';			//邮件主题
//$mail->Body    = $tpl['content'];		//邮件内容
//**
if (is_array($arr_mail)){
	foreach ($arr_mail as $email){
		$url = $cfg['fullurl'] . '?a=cancel&mail=' . urlencode($email) . '&hash=' . md5($email . $cfg['slot']);
		$content = str_replace("__url__", $url, $tpl['content']);
		$mail->Body = $content;
		
		$mail->ClearAddresses();
		$mail->AddAddress($email);
		if(!$mail->Send()){
		   echo "Message could not be sent.<$email> <p>\n";
		   echo "Mailer Error: " . $mail->ErrorInfo . "\n";
		}
	}
}
/***/

$mail->SmtpClose();

echo "邮件发送完毕 " . date("Y-m-d H:i:s") . ' ' . (microtime(true) - $s) . "\n\n";